<template>
	<div class="app-container" :style="'height:' + height + 'px'">
		<div style="width: 100%; height: 100%" v-html="poHtmlCode"></div>
		<input type="hidden" name="isSign" id="isSign" />
		<input type="hidden" name="fileId" id="fileId" />
		<input type="hidden" name="fileName" id="fileName" />
		<input type="hidden" name="reportId" id="reportId" />
	</div>
</template>

<script setup name="Index">
import { viewSignForm } from "@/api/report/reportProject";
import { nextTick } from "vue";
const search = window.location.search;
const poHtmlCode = ref("");
const height = ref("");
const fileForm = ref({});
const isAuto = ref(false)

// const { proxy } = getCurrentInstance();

const searchList = search.substring(1).split("&");
fileForm.value = {
	fileId: searchList[0].split(":")[1],
	fileName: searchList[1].split(":")[1],
	reportId: searchList[2].split(":")[1],
};
viewSignForm(fileForm.value).then((res) => {
	poHtmlCode.value = res;
});

function OnPageOfficeCtrlInit() {
	// pageofficectrl.OfficeToolbars = false; //隐藏Office工具栏
	// pageofficectrl.CustomToolbar = false; //隐藏自定义工具栏
	// PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
	pageofficectrl.AddCustomToolButton("保存", "Save(false)", 1)
}
function AfterDocumentOpened() {
	// PageOffice的文档打开后事件回调函数

	// 开启强制留痕
	pageofficectrl.DisableSave = true;

	Save(true)
}
function BeforeDocumentSaved() {
	// PageOffice的文档保存前事件回调函数
}
function AfterDocumentSaved() {
	// PageOffice的文档保存后事件回调函数
	if (pageofficectrl.CustomSaveResult == "ok") {
		if (!isAuto.value) {
			alert("保存成功！");
		}
		// window.external.close();
		// var sResult = window.external.CallParentFunc("tolc('" + fileForm.value.reportId + "')");
		// if (sResult !== "poerror:parentlost") {
		// window.external.CallParentFunc("tolc()");
		// }
		return
	} else {
		alert("保存失败！");
	}
}
// function BeforeBrowserClosed(){
//   alert(1);
// }
function Save(isAuto1) {
	isAuto.value = isAuto1
	document.getElementById("isSign").value = 1;
	document.getElementById("fileId").value = fileForm.value.fileId;
	document.getElementById("fileName").value = fileForm.value.fileName;
	document.getElementById("reportId").value = fileForm.value.reportId;
	pageofficectrl.WebSave();
}


onMounted(() => {
	window.Save = Save;
	// 以下的为PageOffice事件的回调函数，名称不能改，否则PageOffice控件调用不到
	window.OnPageOfficeCtrlInit = OnPageOfficeCtrlInit;
	window.AfterDocumentOpened = AfterDocumentOpened;
	window.BeforeDocumentSaved = BeforeDocumentSaved;
	window.AfterDocumentSaved = AfterDocumentSaved;
	var box = document.querySelector(".app-container"); // 根据你的盒子ID选择器进行修改
	var boxDistanceFromTop = box.getBoundingClientRect().top; // 盒子距离顶部的距离
	height.value = window.innerHeight - boxDistanceFromTop - 21; // 视窗口高度减去盒子距离顶部的距离
});

</script>

<style scoped lang="scss"></style>
